//
//  LiuRetweetView.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/3/30.
//  Copyright © 2017年 刘晓晨. All rights reserved.
//

import UIKit
import SnapKit
class LiuRetweetView: UIView {

    //约束
    var bottomConstraint:Constraint?
    
    //viewModel
    var statuse:LiustatuseViewModel? {
        didSet {
            contentLabel.attributedText = statuse?.contentStr
            
            bottomConstraint?.deactivate()
    
            if let picArray = statuse?.homeStatuse?.retweeted_status?.pic_urls,picArray.count > 0 {
                
                picView.isHidden = false
                
                self.snp.makeConstraints { (make) in
                    bottomConstraint = make.bottom.equalTo(picView).offset(homeMargin).constraint
                }
                
                picView.picArray = picArray
            } else {
  
                picView.isHidden = true
    
                self.snp.makeConstraints { (make) in
                    bottomConstraint = make.bottom.equalTo(contentLabel).offset(homeMargin).constraint
                }
            }
        }
    }

    //懒加载控件
    lazy var contentLabel: UILabel = {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray, text: "")
        label.numberOfLines = 0
        
        return label
    }()
    
    lazy var picView:LiuHomeRetweetPicView = {
        let pictureView = LiuHomeRetweetPicView()
        pictureView.backgroundColor = UIColor.groupTableViewBackground
        return pictureView
        }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setupUI() {

        addSubview(contentLabel)
        addSubview(picView)
        //自动布局
        contentLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(homeMargin)
            make.top.equalTo(self).offset(homeMargin)
            make.right.equalTo(self).offset(-homeMargin)
        }
        
        picView.snp.makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp.bottom).offset(homeMargin).priority(.low)
            make.left.equalTo(self).offset(homeMargin)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        
        self.snp.makeConstraints { (make) in
            bottomConstraint = make.bottom.equalTo(picView).offset(homeMargin).constraint
        }
    }

}


